/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-11-18 22:15:27
 * @LastEditors: 胡涛
 * @LastEditTime: 2023-12-16 20:55:42
 */

import {
  FullAuditedAggregateRoot,
  PagedAndSortedResultRequestDto,
} from "../types";

export interface ReportCategoryConfigDto {
  id: string;
  type: number;
  parentId: string;
  name: string;
  status: boolean;
  remarks: string;
}
export interface ReportCategoryConfigTreeDto {
  id: string;
  type: number;
  parentId: string;
  name: string;
  status: boolean;
  remarks: string;
  children?: Array<ReportCategoryConfigTreeDto>;
}

export interface GetReportCategoryConfigInputDto
  extends PagedAndSortedResultRequestDto {
  Type: number;
  ParentId: string;
  Status: boolean;
}

export interface GetReportCategoryConfigTreeInputDto {
  Type: number;
  Status: boolean;
}

export interface ReportConfigDto extends FullAuditedAggregateRoot<string> {
  categoryId: string;
  name: string;
  code: string;
  permissionName: string;
  dataSource: ReportSourceConfig;
  requestOptions: Array<ReportRequestFieldItem>;
  reportColumns: Array<ReportColumnConfig>;
  summaryColumns: Array<SummaryColumnConfig>;
  reportProps: Record<string, any>;
  sortIndex: number;
  status: boolean;
  remarks: string;
}
export interface ReportSourceConfig {
  apiConfigCode: string;
  remoteUrl: string;
  totalField?: string;
  itemsField?: string;
  summaryField?: string;
  itemsHandler?: string;
  requireHandler?: boolean;
  isPaged: boolean;
  hasSummary: boolean;
}
export interface ReportRequestFieldItem {
  name: string;
  description: string;
  defaultValue: string;
  type: number;
  title: string;
  formatter: ReportRequestFieldFormatter;
  componentOptions: ComponentOptions;
  displayRole?: DisplayRoleOption;
}

export interface ReportRequestFieldFormatter {
  type: RequestFieldFormatterType;
  name: string;
  handler: string;
}

export interface ComponentOptions {
  name: string;
  className: string;
  styles: Record<string, any>;
  props: Record<string, any>;
}

export interface DisplayRoleOption {
  visible: boolean;
  roles: Array<RoleConditionItem>;
}

export interface RoleConditionItem {
  sourceName: string;
  matchType?: RoleMatchType;
  roleValue: string;
}

export interface ReportColumnConfig {
  name: string;
  title: string;
  formatType: ReportFormatDataType;
  sortIndex: number;
  width: number;
  align: string;
  formula: string;
  formatter: string;
  sortable: boolean;
  styles: Record<string, any>;
  props: Record<string, any>;
  formatOptions: Partial<FormatOptions>
}

export type ReportFormatDataType = "default" | "string" | "json" | "number" | "boolean" | "date" | "dictionary" | "enum" | "user" | "organize" | "enterprise" | "region" | "project" | "custom";


/**
 * 格式化选项
 */
export interface FormatOptions {
  type: ReportFormatDataType;
  name: string;
  valueFormat: string;
  trueValue: string;
  falseValue: string;
  prefix: string;
  suffix: string;
  precision: number;
}

export interface SummaryColumnConfig {
  name: string;
  bindType: 1;
  summaryType: 0;
  bindField: string;
  value: string;
  digit: 0;
}

export interface GetReportConfigInputDto
  extends PagedAndSortedResultRequestDto {
  CategoryId: string;
  Code: string;
  Name: string;
  Status: boolean;
}

export interface HttpApiConfigDto extends FullAuditedAggregateRoot<string> {
  categoryId: string;
  name: string;
  code: string;
  permissionName: string;
  allowAnonymous: boolean;
  requestOptions: Array<RequestFieldItem>;
  httpMethod: 1;
  scriptContent: string;
  demoSchema: string;
  errorResponse: string;
  sortIndex: number;
  status: boolean;
  remarks: string;
}

export interface ExportExcelInputDto {
  queryParamaters: Record<string, any>;
  itemsKey: string;
  summaryKey: string;
  options: Partial<ExportExcelOption>;
}

export interface ExportExcelOption {
  drawCellBorder: boolean;
  rowHeight: number;
  autoSizeColumn: boolean;
  dateTimeFormatter: string;
  sheetName: string;
  caption: string;
  headerRows: Array<HeaderRow>;
  hideColumnTitleRow: boolean;
  columns: Array<ExportColumn>;
  footerContent: string;
}

export interface ExportColumn {
  caption: string;
  fieldName: string;
  width: number;
  dataType?: any;
  validate?: {
    options: Array<{
      cellValue: string;
      cellText: string;
    }>;
    min: 0;
    max: 0;
  };
}

export interface HeaderRow {
  items: Array<HeaderCellSpan>;
}

export interface HeaderCellSpan {
  value: string | number | boolean;
  span?: number;
  rowSpan?: number;
  align?: HorizontalAlignment;
}

export interface GetHttpApiConfigInputDto
  extends PagedAndSortedResultRequestDto {
  CategoryId: string;
  Code: string;
  Name: string;
  Status: boolean;
}

export interface RequestFieldItem {
  name: string;
  description: string;
  defaultValue: string;
}

export enum HttpMethodEnum {
  GET = 1,
  POST = 2,
  PUT = 3,
  DELETE = 4,
}

export enum RequestFieldFormatterType {
  None = 0,
  User = 1,
  Organize = 2,
  Area = 3,
  Dictionary = 4,
  Enum = 5,
  CustomOptions = 6,
  Callback = 7,
}

export enum RoleMatchType {
  /** 等于 */
  Equal = 1,

  /** 不等于 */
  NotEqual = 2,

  /** 包含 */
  Contains = 3,

  /** 大于 */
  GreaterThan = 4,

  /** 小于 */
  LessThan = 5,

  /** 大于等于 */
  EqualAndGreaterThan = 6,

  /** 小于等于 */
  EqualAndLessThan = 7,
}

export enum HorizontalAlignment {
  General = 0,
  Left = 1,
  Center = 2,
  Right = 3,
  Fill = 4,
  Justify = 5,
  CenterSelection = 6,
  Distributed = 7,
}
